package library.logic;


import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

/**
 * User: RockCrazy
 * Date: 09.12.11
 * Time: 16:05
 */

public final class Config
{

	/** Driver для MySQL*/
	public static String DATABASE_DRIVER;
	/** URL для БД*/
	public static String DATABASE_URL;
	/** Логин для доступа к БД */
	public static String DATABASE_LOGIN;
	/** Пароль для доступа к БД */
	public static String DATABASE_PASSWORD;


	/** Путь к OpenOffice  */
	public static String URL_OPEN_OFFICE;

	/** Путь к файлу-отчету  */
	public static String URL_FILE_TEMPLATE;

	/** Для запуска в среде IDE**/
	public static boolean DEBUG = true;

	//*******************************************************************************************


	public static final String  CONFIGURATION_FILE          = "./config/main.properties";
	//public static final String  CONFIGURATION_FILE          = "/home/Sergey/Logovo/progi/DBMobilkO/build/dist/config/main.properties";

	public static void load()
	{
		try
		{

			Properties programSettings	= new Properties();
			if(DEBUG)
			{
				InputStream is              = new FileInputStream(new File("library/logic/main.properties"));
				programSettings.load(is);
				is.close();
			}
			else
			{
				InputStream is              = new FileInputStream(new File(CONFIGURATION_FILE));
				programSettings.load(is);
				is.close();
			}


			DATABASE_DRIVER             = programSettings.getProperty("Driver", "com.mysql.jdbc.Driver");
			DATABASE_URL                = programSettings.getProperty("URL", "jdbc:mysql://localhost:3306/dblibrary?useUnicode=true&characterEncoding=UTF8");
			DATABASE_LOGIN              = programSettings.getProperty("Login", "root");
			DATABASE_PASSWORD           = programSettings.getProperty("Password", "");
			URL_OPEN_OFFICE				= programSettings.getProperty("UrlOpenOficce", "/usr/lib/openoffice/program/soffice");
			URL_FILE_TEMPLATE			= programSettings.getProperty("UrlFileTemplate", "./template/template.odt");

		}
		catch (Exception e)
		{
			e.printStackTrace();
			throw new Error("Failed to Load "+CONFIGURATION_FILE+" File.");
		}
	}
}
